package com.wolfalpha.lwtool.service.impl;

import java.util.List;
import java.util.Map;

import com.wolfalpha.lwtool.constant.Application;
import com.wolfalpha.lwtool.constant.Constant;
import com.wolfalpha.lwtool.exception.InternetErrorException;
import com.wolfalpha.lwtool.service.ZQService;
import com.wolfalpha.lwtool.util.JsonUtil;
import com.wolfalpha.lwtool.vo.FFCity;
import com.wolfalpha.lwtool.vo.FFInfoJson;
import com.wolfalpha.lwtool.vo.FFJobInfo;
import com.wolfalpha.lwtool.vo.FFJobJson;
import com.wolfalpha.lwtool.vo.FFListJob;

/**
 * 抓取服务实例
 * 发发
 * @author ttStudio
 * 
 */
public class ZQServiceImpl implements ZQService {

	// @Override
	// public List<Job> getJobList(int category) throws ParseException,
	// IOException {
	// HttpResponse message = null;
	// try {
	// message = Application.getClient().unSafeIdmpRequest(
	// "http://app.fafajob.com/parttimeJob/list.do",
	// new BasicNameValuePair("competenceCode",
	// "w1T01f5AlH5zpGyaQLW9zOVf%2BlcMExInMtzDIgeA2aA%3D%0A"),
	// new BasicNameValuePair("provincesName", "江苏省"),
	// new BasicNameValuePair("cityName","南京市"),
	// new BasicNameValuePair("pjType","ordinary"),
	// new BasicNameValuePair("apiType","index"),
	// new BasicNameValuePair("sign","612303b8e1ef25981a5178b3d3ef8ad"),
	// new BasicNameValuePair("longitude","118.781809"),
	// new BasicNameValuePair("latitude","32.050058"),
	// new BasicNameValuePair("client_type","app_client"),
	// new BasicNameValuePair("jobNature",""),
	// new BasicNameValuePair("paymentMeans",""),
	// new BasicNameValuePair("jobNature",""),
	// new BasicNameValuePair("jobNature","")
	// );
	// } catch (Exception e) {
	// }
	// if(message == null)return null;
	// int status = message.getStatusLine().getStatusCode();
	// if (status == 200) {
	// String data = EntityUtils.toString(message.getEntity());
	// System.out.println(data);
	// // java.lang.reflect.Type type = new TypeToken<ArrayList<Job>>() {
	// // }.getType();
	// // List<Job> jobList = JsonUtil.parseJson(data, type);
	// // return jobList;
	// } else {
	// }
	// return null;
	// }

	@Override
	public List<FFListJob> getJobs(String strUrlPath, Map<String, String> params)
			throws InternetErrorException {
		String data = Application.getClient().submitPostData(strUrlPath,
				params, Constant.encode);
		FFJobJson jjson = JsonUtil.parseJson(data, FFJobJson.class);
		return jjson.getJobs();
	}

	@Override
	public List<FFListJob> getMoreJobs(String strUrlPath, Map<String, String> params)
			throws InternetErrorException {
		String data = Application.getClient().submitPostData(strUrlPath,
				params, Constant.encode);
		FFJobJson jjson = JsonUtil.parseJson(data, FFJobJson.class);
		return jjson.getJobs();
	}

	@Override
	public FFJobInfo getInfo(String strUrlPath, Map<String, String> params)
			throws InternetErrorException {
		String data = Application.getClient().submitPostData(strUrlPath,
				params, Constant.encode);
		try{
			FFInfoJson jjson = JsonUtil.parseJson(data, FFInfoJson.class);
			return jjson.getParttimeJob();
		}catch(Exception e){
			return null;
		}
			
	}

	@Override
	public String postData(String strUrlPath, Map<String, String> params)
			throws InternetErrorException {
		String data = Application.getClient().submitPostData(strUrlPath,
				params, Constant.encode);
		return data;
	}

	@Override
	public List<FFListJob> getRefreshJobs(String strUrlPath,
			Map<String, String> params) throws InternetErrorException {
		String data = Application.getClient().submitPostData(strUrlPath,
				params, Constant.encode);
		FFJobJson jjson = JsonUtil.parseJson(data, FFJobJson.class);
		return jjson.getJobs();
	}

	@Override
	public List<FFCity> getAllCitys() throws InternetErrorException {
		// TODO Auto-generated method stub
		return null;
	}

}
